package com.lighthouse.note.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.UUID;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 小记对象
 * 
 * @author ysz
 * @date 2024-09-28
 */
@Document(indexName = "note-info-000001")
@Data
public class KnowledgeNote
{
    private static final long serialVersionUID = 1L;

    /** 小记主键 */
    @Id
    @Field(type = FieldType.Keyword)
    private String noteId;

    /** 标签 */
    @Field(type = FieldType.Text)
    private String noteTags;

    /** 标签名称 */
    @Field(type = FieldType.Text)
    private List<String> noteTagsName;

    /** 小记描述 */
    @Field(type = FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
    private String noteDesc;

    /** 发布状态  0-草稿  1-待审核  2-已发布  3-存档  4-已删除*/
    @Field(type = FieldType.Keyword)
    private String noteStatus;

    /** 小记类型 */
    @Field(type = FieldType.Keyword)
    private String noteType;

    @Field(type = FieldType.Keyword)
    private String createBy;

    @Field(type = FieldType.Date, format = DateFormat.date)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate createTime;

    @Field(type = FieldType.Keyword)
    private String updateBy;

    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second_millis)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    @Field(type = FieldType.Long)
    private Long createUser;

    @Field(type = FieldType.Keyword)
    private String createUserAvatar;

    public String getNoteId() {
        return noteId;
    }

    public void setNoteId(String noteId) {
        this.noteId = noteId;
    }

    public String getNoteTags() {
        return noteTags;
    }

    public void setNoteTags(String noteTags) {
        this.noteTags = noteTags;
    }

    public List<String> getNoteTagsName() {
        return noteTagsName;
    }

    public void setNoteTagsName(List<String> noteTagsName) {
        this.noteTagsName = noteTagsName;
    }

    public String getNoteDesc() {
        return noteDesc;
    }

    public void setNoteDesc(String noteDesc) {
        this.noteDesc = noteDesc;
    }

    public String getNoteStatus() {
        return noteStatus;
    }

    public void setNoteStatus(String noteStatus) {
        this.noteStatus = noteStatus;
    }

    public String getNoteType() {
        return noteType;
    }

    public void setNoteType(String noteType) {
        this.noteType = noteType;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public LocalDate getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDate createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Long getCreateUser() {
        return createUser;
    }

    public void setCreateUser(Long createUser) {
        this.createUser = createUser;
    }

    public String getCreateUserAvatar() {
        return createUserAvatar;
    }

    public void setCreateUserAvatar(String createUserAvatar) {
        this.createUserAvatar = createUserAvatar;
    }

    @Override
    public String toString() {
        return "Knowledgenote{" +
                "noteId='" + noteId + '\'' +
                ", noteTags=" + noteTags +
                ", noteTagsName=" + noteTagsName +
                ", noteDesc='" + noteDesc + '\'' +
                ", noteStatus='" + noteStatus + '\'' +
                ", noteType='" + noteType + '\'' +
                ", createBy='" + createBy + '\'' +
                ", createTime=" + createTime +
                ", updateBy='" + updateBy + '\'' +
                ", updateTime=" + updateTime +
                ", createUser=" + createUser +
                ", createUserAvatar='" + createUserAvatar + '\'' +
                '}';
    }

    public void setCreateInfo() {
        this.noteId = UUID.fastUUID().toString();
        this.createBy = SecurityUtils.getLoginUser().getUser().getNickName();
        this.createTime = LocalDate.now();
        this.createUser = SecurityUtils.getLoginUser().getUser().getUserId();
        this.createUserAvatar = SecurityUtils.getLoginUser().getUser().getAvatar();
    }

    public void setUpdateInfo() {
        this.updateBy = SecurityUtils.getLoginUser().getUser().getNickName();
        this.updateTime = LocalDateTime.now();
    }
}
